package com.fan.shop.mock;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.fan.shop.dao.StockReqDaoImpl;
import com.fan.shop.dao.StockReqLineDaoImpl;
import com.fan.shop.domain.StockReqLine;
import com.fan.shop.domain.StockReqLineId;
import com.fan.shop.hibernate.utils.HibernateUtil;

public class StockReqMock {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		StockReqMock mock = new StockReqMock();
		mock.insertStockReqLines();
		//mock.testStockReqLines();
		
	}
	
	public void testStockReqLines()
	{
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.getCurrentSession();
		Transaction transaction = session.beginTransaction();

		StockReqDaoImpl stockReqDaoImpl = new StockReqDaoImpl();
		stockReqDaoImpl.setSessionFactory(sessionFactory);
		
		List<StockReqLine> list = stockReqDaoImpl.getStockReqLines("stockReq_1");
//		for(StockReqLine stockReqLine : list)
//		{
//			System.out.println(stockReqLine.getQty());
//		}
		
		BigDecimal t1 = new BigDecimal(2.0);
		BigDecimal t2 = new BigDecimal(2.0);
		System.out.println(t1.add(t2));
		System.out.println(stockReqDaoImpl.getTotalQty("stockReq_1"));
		System.out.println(stockReqDaoImpl.getTotalPrice("stockReq_1"));
		
	}

	
	public void insertStockReqLines()
	{
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.getCurrentSession();
		Transaction transaction = session.beginTransaction();

		StockReqLineDaoImpl stockReqLineDaoImpl = new StockReqLineDaoImpl();
		stockReqLineDaoImpl.setSessionFactory(sessionFactory);
		
		for(int i = 0; i < 50; i++)
		{
			StockReqLine stockReqLine = new StockReqLine();
			StockReqLineId stockReqLineId = new StockReqLineId("stockReq_1", "ITEM2_0001");
			stockReqLine.setId(stockReqLineId);
			stockReqLine.setLineStatus("e");
			stockReqLine.setOfficerCode("ADM");
			stockReqLine.setPrice(new BigDecimal(5.0));
			stockReqLine.setQty(10);
			stockReqLine.setStoreCode("LG");
			stockReqLine.setTransactionDate(new Date(System.currentTimeMillis()));
			
			stockReqLineDaoImpl.addStockReqLine(stockReqLine);
			
		}
		transaction.commit();
	}
}
